package MyAdmin.Controller;

import MyFramePro.Domain.Dto.AddArticleDto;
import MyFramePro.Domain.Entity.Menu;
import MyFramePro.Domain.ResponseResult;
import MyFramePro.Domain.Vo.ArticleInfoVo;
import MyFramePro.Service.Impl.ArticleServiceImpl;
import MyFramePro.Service.Impl.MenuServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/content/article")
public class ArticleController {

    @Resource
    private ArticleServiceImpl articleService;

    @Resource
    private MenuServiceImpl menuService;

    /**
     * 这里是新增博文的功能
     */
    @PreAuthorize("@myPer.hasAuthority('/content/article')") //这里进行传入权限信息
    @PostMapping
    public ResponseResult addArticle(@RequestBody AddArticleDto addArticleDto){

        return articleService.addArticle(addArticleDto);
    }


    /**
     * 这里是进行文章列表的查询功能
     * @pageNum: 页码
     * @pageSize: 每页条数
     * @title：  文章标题
     * @summary：  文章摘要
     */
    @GetMapping(value = "/list")
    public ResponseResult selectArticle(Integer pageNum,Integer pageSize,String title,String summary){

        return articleService.behindArticleList(pageNum,pageSize,title,summary);
    }


    /**
     * 这里是查询文章详情的功能
     */
    @GetMapping("{id}")
    public  ResponseResult  articleInfo(@PathVariable("id")Long id){

        return articleService.getArticleInfo(id);
    }


    /**
     * 这里是更新文章的功能
     */
    @PutMapping
    public ResponseResult updateArticle(@RequestBody ArticleInfoVo articleInfoVo){

        return articleService.updateArticle(articleInfoVo);
    }


    /**
     * 这里是删除文章的功能
     */
    @DeleteMapping("{id}")
    public ResponseResult deleteArticle(@PathVariable("id") Long id){

        return articleService.deleteArticle(id);
    }

}
